package com.digitaldreamers.framework.scene.layer;

import org.andengine.entity.scene.CameraScene;

public abstract class ManagedLayer extends CameraScene {
	protected boolean mIsLoaded;
	protected boolean mIsUnloadOnHidden;
	
	public ManagedLayer() {
		this(false);
	}
	
	public ManagedLayer(boolean isUnloadOnHidden) {
		this.mIsLoaded = false;
		this.mIsUnloadOnHidden = isUnloadOnHidden;
		this.setBackgroundEnabled(false);
	}
	
	public void onShowManagedLayer() {
		if(!this.mIsLoaded) {
			this.mIsLoaded = true;
			this.onLoadLayer();
		}
		this.setIgnoreUpdate(false);
		this.onShowLayer();
	}
	
	public void onHideManagedLayer() {
		this.setIgnoreUpdate(true);
		this.onHideLayer();
		if(this.mIsUnloadOnHidden) {
			this.onUnloadLayer();
		}
	}
	
	public abstract void onLoadLayer();
	public abstract void onShowLayer();
	public abstract void onHideLayer();
	public abstract void onUnloadLayer();
}